name: CodeQL Analysis

on:
  workflow_call:
  schedule:
    - cron: '0 0 * * *'

env:
  NODE_OPTIONS: --max_old_space_size=6144

jobs:
  analyze:
    name: Analyze
    runs-on: ubuntu-latest
    permissions:
      actions: read
      contents: read
      security-events: write
    strategy:
      fail-fast: true
      matrix:
        language:
          - javascript
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Prepare
        uses: ./.github/actions/prepare
        with:
          build: false

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          config-file: ./.github/codeql/codeql-config.yml

      - name: Perform CodeQL analysis
        uses: github/codeql-action/analyze@v3
        with:
          upload: false
          output: sarif-results

      - name: Upload Artifact
        uses: actions/upload-artifact@v4
        with:
          name: sarif-results
          path: sarif-results
          retention-days: 1

      - name: Upload SARIF
        uses: github/codeql-action/upload-sarif@v3
        with:
          sarif_file: sarif-results/javascript.sarif
